/* eslint-disable no-continue */
/* eslint-disable no-prototype-builtins */
/* eslint-disable no-param-reassign */
interface IObj {
  [key: string]: any;
}

function mergeJSON(obj1: IObj, obj2: IObj) {
  let key;
  // eslint-disable-next-line no-restricted-syntax
  for (key in obj2) {
    if (!obj2.hasOwnProperty(key)) {
      continue;
    }
    // 如果target(也就是obj1[key])存在，且是对象的话再去调用deepMerge，否则就是obj1[key]里面没这个对象，需要与obj2[key]合并
    obj1[key] = obj1[key] && obj1[key].toString() === '[object Object]'
      ? mergeJSON(obj1[key], obj2[key])
      : (obj1[key] = obj2[key]);
  }
  return obj1;
}

export default mergeJSON;
